package com.sugon.consts;

/**
 * 设备检验周期枚举类
 *
 * @author YuXD
 * @since 2021-09-18
 */
public enum DevInspectInterval {

    EVERY_YEAR(12, "一年"),
    EVERY_TOW_YEAR(24, "两年"),
    EVERY_THREE_YEAR(36, "三年");

    Integer months;

    String desc;

    DevInspectInterval(Integer months, String desc) {
        this.months = months;
        this.desc = desc;
    }

    public Integer getMonths() {
        return months;
    }

    public String getDesc() {
        return desc;
    }

    /**
     * 根据检验周期文字描述获取对应的检验周期枚举
     *
     * @param desc 检验周期文字描述
     * @return
     */
    public static DevInspectInterval getMonthsByDesc(String desc) {
        DevInspectInterval[] values = values();
        for (DevInspectInterval value : values) {
            if (value.getDesc().equals(desc)) {
                return value;
            }
        }
        return null;
    }

    /**
     * 根据月份描述获取对应的检验周期枚举
     *
     * @param months 月份
     * @return
     */
    public static DevInspectInterval getByMonths(Integer months) {
        if (months != null) {
            DevInspectInterval[] values = values();
            for (DevInspectInterval value : values) {
                if (value.getMonths().equals(months)) {
                    return value;
                }
            }
        }
        return null;
    }
}
